package db;

import java.sql.SQLException;
import java.util.List;

import alList.Grade;
import alList.Lesson;
import alList.Student;
public class DBadd extends DBoc{
	
	public void addStuInfo(List<Student> stu) throws SQLException {
	//String num, String name, String cla, String spec, String depart;
		if (connection == null)
			Connect();
		if (statement == null) 
			statement = connection.createStatement();
		
		for (Student student : stu) {
			String sql = "insert into stu_info values ('" + student.getNum() + "', '" + student.getName() + "', '"
					+ student.getCla() + "', '" + student.getSpec() + "', '" + student.getDepart() + "')";
			statement.execute(sql);
		}
	}

	public void addClaInfo(List<Lesson> cla) throws SQLException {
	//String num, String name, double credit, String teach, String nature, String exam
		if (connection == null)
			Connect();
		if (statement == null) 
			statement = connection.createStatement();
		
		for (Lesson lesson : cla) {
			String sql = "insert into cla_info values ('" + lesson.getNum() + "', '" + lesson.getName() + "', '"
					+ lesson.getCredit() + "', '" + lesson.getTeach() + "', '" + lesson.getNature() + "', '" + lesson.getExam() + "')";
			statement.execute(sql);
		}
	}
	
	public void addGradeInfo(List<Grade> gra) throws SQLException {
	//String claNum, String stuNum, double grade
		if (connection == null)
			Connect();
		if (statement == null)
			statement = connection.createStatement();
		
		for (Grade grade : gra) {
			String sql = "insert into grade_info values ('" + grade.getClaNum() + "', '" + grade.getStuNum()
					 + "', '" + grade.getScore() + "', '" + grade.getGrade() + "', '" + grade.getMarkType() + "')";
			statement.execute(sql);
		}
	}

	
}
